<?php
/**
 * JoiEditor - Joostina WYSIWYG Editor
 *
 * Backend controller
 *
 * @version 1.0 beta 3
 * @package JoiEditor
 * @subpackage	Admin
 * @filename admin.joieditor.ajax.php
 * @author JoostinaTeam
 * @copyright (C) 2008-2010 Joostina Team
 * @license see license.txt
 *
 **/

defined('_VALID_MOS') or die();

require_once ($mainframe->getPath('class'));

switch($task) {

	default:
		echo 'error task';
		break;

	case 'refresh_buttons':
		refresh_buttons();
		break;
}


function refresh_buttons() {

	$buttons1 = mosGetParam($_REQUEST, 'buttons1', '');
	$buttons2 = mosGetParam($_REQUEST, 'buttons2', '');
	$buttons3 = mosGetParam($_REQUEST, 'buttons3', '');
	$buttons4 = mosGetParam($_REQUEST, 'buttons4', '');

	$editor = &joiEditor::getInstance();

	$_classes = $editor->_classes;
	$add_buttons = $editor->get_add_buttons();

	$all_but = array($buttons1,$buttons2,$buttons3,$buttons4 );

	$arr = array();

	foreach($all_but as $row_but) {
		$row_but_arr = 	explode(',', $row_but);

		$return = '';
		foreach($row_but_arr as $v ) {
			$but = $editor->draw_button($v);
			if($v) {
				$return .=  '<li id="'.$v.'">'.$but.'</li>';
			}
		}
		$arr[] = $return;

	}

	if(function_exists('json_encode')) {
		echo json_encode(array("0"=>$arr[0],"1"=>$arr[1],"2"=>$arr[2],"3"=>$arr[3]));
	}
	else {
		echo joiEditorHelper::array_to_json(array("0"=>$arr[0],"1"=>$arr[1],"2"=>$arr[2],"3"=>$arr[3]));
	}
}